<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
Waiting for other Constraints
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot119.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot117.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc263">18.3</A>&nbsp;&nbsp;Waiting for other Constraints</H2>
<A NAME="@default1061"></A>
The <B>constrained</B> list in the <B>suspend</B> attribute
is used for instance in generic predicates which have to be
notified about the possible change of the state of a variable,
especially its unifyability with other terms.
Our example with the <B>dif</B> predicate could be for instance
extended to work with finite domain or other constrained
variables.
The modification is fairly simple:
<UL CLASS="itemize"><LI CLASS="li-itemize">
When a variable in one term is matched against a subterm of the
other term, it might not necessarily be unifyable with it, because
there might be other constraints imposed on it.
Therefore, <A HREF="../bips/kernel/termcomp/not_unify-2.html"><B>not_unify/2</B></A><A NAME="@default1062"></A> must be used to test it explicitly.<BR>
<BR>
<LI CLASS="li-itemize">The suspension should be woken not only on binding, but
on any constraining and thus the <B>constrained</B> list
has to be used.
</UL>
The predicate <B>compare_args/5</B> is thus changed as follows:
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
compare_args(_, _, _, _, Yes) :-
    nonvar(Yes).
compare_args(A1, A2, Link, NewLink, Yes) :-
    var(Yes),
    (A1 == A2 -&gt;
        Link = NewLink
    ;
    (var(A1);var(A2)) -&gt;
        (not_unify(A1, A2) -&gt;
            Yes = yes
        ;
            suspend(compare_args(A1, A2, Link, NewLink, Yes), 3,
  [[A1|A2]-&gt;constrained, Yes-&gt;inst])
        )
    ;
        compare_terms(A1, A2, Link, NewLink, Yes)
    ).
</PRE></BLOCKQUOTE>
Now our <B>dif3/4</B> predicate yields correct results even for
constrained variables:
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
[eclipse 1]: dif3(A, B, Y, N), A::1..10, B::20..30.

Y = yes
N = N
A = A{[1..10]}
B = B{[20..30]}
yes.
[eclipse 2]: dif3(A, B, Y, N), A::1..10, B = 5, A ## 5.
 
Y = yes
N = N
B = 5
A = A{[1..4, 6..10]}
yes.
[eclipse 18]: dif3(A, B, Y, N), A + B $= 1, A $= 1/2.

Y = Y
N = no
B = 1 / 2
A = 1 / 2
yes.

</PRE></BLOCKQUOTE>
<HR>
<A HREF="umsroot119.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot117.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
</BODY>
</HTML>
